/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ez2find.manager;

import com.ez2find.model.Area;
import com.ez2find.model.Site;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Owner
 */
@Stateless
public class AreaManagerBean implements AreaManagerLocal {
    
    @PersistenceContext
    private EntityManager em;
    
    public void create(Area area)throws Exception {
        em.persist(area);
    }
 
    public void update(Area area)throws Exception {
        em.merge(area);
    }
    
    public void delete(Area area)throws Exception {
        area=em.merge(area);
        em.remove(area);
    }
    
    public Area find(long id){
        return em.find(Area.class,id);
    }

    public List<Area> listAll(){
        Query query=em.createNamedQuery("listAllAreas");
        List<Area> result=query.getResultList();
        return result;
    }
 
    public List<Area> areasSite(Site site){
        Query query=em.createNamedQuery("areasSite");
        query.setParameter("site", site);
        List<Area> result=query.getResultList();
        return result;
    }
    
}
